<template>
  <div class="form-layout">
    <!--左侧导航-->
    <div class="nav-left">
      <customAnchor
        :itemList="[
          { name: 'box-base', title: '基础信息' },
          { name: 'box-user', title: '病人信息' },
          { name: 'box-dtl', title: '消耗明细' },
        ]"
      />
    </div>

    <!--表单区域-->
    <div class="form-right" ref="formRight">
      <div id="box-base" class="box-title">基础信息</div>
      <customForm :data="form" :rules="propRules" ref="editForm" :disabled="propReadonly">
        <template #content>
          <customFormItem
            label="实物仓库" name="warehouseName" :parent="_self" :form="form"
            :readonly="true" :showSelectIcon="true"
            @focus="utilSelect.warehouse(warehouseNameChange)"
            :disabled="cpHasDtl"
            help="有明细后不可修改"
          />
          <customFormItem
            label="开立科室" name="deptName" :parent="_self" :form="form"
            :readonly="true" :showSelectIcon="true"
            @focus="utilSelect.dept(deptNameChange)"
            :disabled="cpHasDtl"
            help="有明细后不可修改"
          />

          <customFormItem
            label="执行科室" name="execDeptName" :parent="_self" :form="form"
            :readonly="true" :showSelectIcon="true"
            @focus="utilSelect.dept(execDeptNameChange)"
            :disabled="cpHasDtl"
            help="有明细后不可修改"
          />

          <customFormItem
            label="消耗日期" name="busDate" :parent="_self" :form="form"
            :type="constCommon.formItemType.datePicker.name"
          />

          <customFormItem label="冲红" name="flagUseRedType" :parent="_self" :form="form"
                          :disabled="cpHasDtl"
                          help="有明细后不可修改"
                          :type="constCommon.formItemType.switch.name"
                          :config="{flagValueBoolean: true}"
          />

          <customFormItem  v-if="cpFlagInput" label="HIS单号" name="refKey" :parent="_self" :form="form"/>
          <customFormItem
            v-else
            label="HIS单号" name="refKey" :parent="_self" :form="form"
            :readonly="true" :showSelectIcon="true"
            @focus="utilSelect.hisBill(hisBillChange)"
            :disabled="cpHasDtl"
            help="有明细后不可修改"
          />
          <customFormItem
            label="消耗单号" name="busKey" :parent="_self" :form="form"
            disabled
            :config="{defaultValue: '自动获取'}"
          />

          <customFormItem
            label="消耗类型" name="busType" :parent="_self" :form="form" disabled
            :type="constCommon.formItemType.selectDict.name"
            :config="{ dictType: constCommon.dictType.deptUseType }"
          />

          <customFormItem label="金额" name="amount" :parent="_self" :form="form" disabled  />
          <customFormItem label="备注" name="remark" :parent="_self" :form="form" />

          <div id="box-user" class="box-title">病人信息</div>

          <customFormItem  v-if="cpFlagInput" label="手术单号" name="oprtCode" :parent="_self" :form="form"/>
          <customFormItem
            v-else
            label="手术单号" name="oprtCode" :parent="_self" :form="form"
            :readonly="true" :showSelectIcon="true"
            @focus="utilSelect.oprt(oprtChange)"
            :disabled="cpHasDtl"
            help="有明细后不可修改"
          />
          <customFormItem
            label="手术名称" name="oprtName" :parent="_self" :form="form"
            :disabled="cpHasDtl"
            help="有明细后不可修改"
          />
          <customFormItem
            label="手术日期" name="oprtDate" :parent="_self" :form="form"
            :type="constCommon.formItemType.datePicker.name"
            :disabled="cpHasDtl"
            help="有明细后不可修改"
          />


          <customFormItem  v-if="cpFlagInput" label="患者" name="patientName" :parent="_self" :form="form"/>
          <customFormItem
            v-else
            label="患者" name="patientName" :parent="_self" :form="form"
            :readonly="true" :showSelectIcon="true"
            @focus="utilSelect.patient(selectChangePatient)"
            :disabled="cpHasDtl"
            help="有明细后不可修改"
          />
         <!-- <customFormItem
            label="患者性别"
            name="patientGender"
            :parent="_self"
            :form="form"
            :type="constCommon.formItemType.selectStatic.name"
            :config="{ options: utils.getDictDataList(constCommon.dictType.commonGender) }"
          />-->

          <customFormItem label="床位" name="bedNo" :parent="_self" :form="form" :disabled="!cpFlagInput"  />
          <customFormItem label="住院号" name="inpatientNo" :parent="_self" :form="form"  :disabled="!cpFlagInput"   />
          <customFormItem label="门诊号" name="outpatientNo" :parent="_self" :form="form"  :disabled="!cpFlagInput"   />
          <customFormItem label="主治医生" name="docNameSug" :parent="_self" :form="form"  :disabled="!cpFlagInput"   />
          <customFormItem label="专家" name="docNameApply" :parent="_self" :form="form"  :disabled="!cpFlagInput"   />
        </template>
      </customForm>

      <div id="box-dtl" class="box-title">消耗明细</div>
      <customTooltip title="扫描标签码添加明细" v-show="!propReadonly">
        <template #title>
          <div>
            正常单据，扫描有效库存即可
          </div>
          <div>
            冲红单据，扫描科室冲红库存
          </div>
        </template>
        <template #content>
          <FortenScan
            ref="scanInputDtl"
            propPlaceholder="扫描标签码添加明细"
            @after-scan="barCodeScan"
            propType="uniqueCode"
            style="width: 450px;margin-top: 10px;"/>
        </template>
      </customTooltip>
      <data-view
        propViewKey="dept_oprt_use_item"
        :propInitData="form"
        :propParentData="propParent.viewFormData"
        ref="childDataView"
        :propsDisableDbClick="true"
        :propParentPage="_self"
        :propAutoFetchData="false"
        @extra-button-click="extraButtonClick"
        :propHideFlowSelect="true"
        @afterTableDataChange="afterTableDataChange"
        :propFlowKey="propParent.propFlowKey"
        :propNoEditRow="true"
      />
    </div>

    <!--冲红明细选择-->
    <tableDrawer
      ref="tableDrawerDtlRed"
      refName="tableDrawerDtlRed"
      viewKey="oprt_use_item_select"
      :queryWrapper="dtlRedqueryWrapper"
      loadForce
      title="请选择需要冲红的明细数据"
      :subtitle="dtlRedSubTitle"
      :widthPer="80"
      :heightPx="-1"
      :widthPx="-1"
    />
  </div>
</template>

<script>
import customAnchor from '@/components/custom/form/customAnchor.vue'

export default {
  data() {
    return {
      form: {},
      viewData: {},
      dtlRedqueryWrapper: null,
      dtlRedSubTitle: '',
      dataListPrint: []
    }
  },
  computed: {
    // 是否有明细
    cpHasDtl() {
      return this.form.countDtl > 0
    },
    // 是否冲红单据
    cpIsRed() {
      return this.form.flagUseRedType == 1
    },
    // 是否是输入页面,如果是，则病人相关信息为手动输入
    cpFlagInput() {
      return this.propParam && this.propParam.flagInput != undefined && this.propParam.flagInput == true
    }
  },
  methods: {
    // 加载明细
    loadDtl() {
      if (!this.$refs.childDataView) {
        return
      }
      let $newWrapper = this.$newWrapper()
      if (this.form.id) {
        $newWrapper.eq('dept_oprt_use_id', this.form.id)
      } else {
        $newWrapper.ne(1, 1)
      }
       this.$refs.childDataView.setQueryWrapper($newWrapper)
    },

    // 扩展按钮事件
    extraButtonClick({ button, data, index }) {
      let buttonKey = button.key
      if (buttonKey === 'chooseMaterials') { // 选择耗材
        if (!this.formValid()) {
          return false
        }
        if (this.cpIsRed) {
          this.dtlRedqueryWrapper = this.$newWrapper()
          if (this.strings.isNotBlank(this.form.oprtCode)) {
            this.dtlRedSubTitle = '当前单据的手术相关计费'
            this.dtlRedqueryWrapper.eq('oprtCode', this.form.oprtCode)
          }
          this.$refs.tableDrawerDtlRed.show(this.saveBatchItem, true)
        } else {
          this.utilSelect.stockMore(this.saveBatchItem, this.form.warehouseId, true)
        }
      }
    },
    // 实物仓库 选择
    warehouseNameChange(row) {
      this.$set(this.form, 'warehouseId', row.id)
      this.$set(this.form, 'warehouseName', row.name)
    },
    // 开立科室 选择
    deptNameChange(row) {
      this.$set(this.form, 'deptId', row.id)
      this.$set(this.form, 'deptName', row.name)
    },
    // 执行科室 选择
    execDeptNameChange(row) {
      this.$set(this.form, 'execDeptId', row.id)
      this.$set(this.form, 'execDeptName', row.name)
    },
    // 手术单号 选择
    oprtChange(row) {
      this.$set(this.form, 'oprtId', row.id)
      this.$set(this.form, 'oprtName', row.name)
      this.$set(this.form, 'docNameSug', row.doctorNameSug)
      this.$set(this.form, 'docNameApply', row.doctorNameApply)
      this.$set(this.form, 'oprtDate', row.date)
      this.$set(this.form, 'oprtCode', row.code)
      this.$set(this.form, 'patientId', row.patientId)
      this.$set(this.form, 'patientName', row.patientName)
      this.$set(this.form, 'patientAge', row.age)
      this.$set(this.form, 'inpatientNo', row.inpatientNo)
      this.$set(this.form, 'bedNo', row.bedNo)
      this.$set(this.form, 'patientNo', row.no)
    },
    //患者选择后
    selectChangePatient(row) {
      this.$set(this.form, 'patientId', row.id)
      this.$set(this.form, 'patientName', row.name)
      this.$set(this.form, 'patientAge', row.age)
      this.$set(this.form, 'inpatientNo', row.inpatientNo)
      this.$set(this.form, 'bedNo', row.bedNo)
      this.$set(this.form, 'patientNo', row.no)
    },
    //HIS单号 选择后
    hisBillChange(row) {
      this.$set(this.form, 'refKey', row.hisKey)
    },
    // 扫描后
    barCodeScan(scanValue) {
      if (!this.formValid()) {
        return false
      }
      this.utilVue.loadShow(true)
      let that = this
      this.$ajax.get(`/wm/stock/getStockByUniqueCode?uniqueCode=${scanValue}`).then((resp) => {
        this.utilVue.loadHide()
        if (resp.code == 0) {
          if (!resp.data) {
            this.utilMessage.error('库存未找到')
            return
          }

          if (this.strings.isNotBlank(resp.data.lockId)) {
            this.utilMessage.error(resp.data.lockInfo, 5000)
            return
          }
          if (this.form.warehouseId != resp.data.warehouseId) {
            this.utilMessage.error('该耗材没有进行科室验收，不能进行消耗计费')
            return
          }

          if (this.form.flagUseRedType && resp.data && resp.data.packageQty > 0) {
            this.utilMessage.warning('该唯一码有库存，不可以冲红，如需消耗，请将单据类型改为非冲红单据')
            return
          }
          this.saveBatchItem([resp.data])
        }
      })
    },
    // 添加明细
    saveBatchItem(stockList) {
      //主单据未保存
      if(this.propParent.cpFormNew) {
        this.propParent.ocAsynSaveViewForm(() => {
          this._saveBatchItem(stockList)
        })
        return
      }
      this._saveBatchItem(stockList)
    },

    // 添加明细
    _saveBatchItem(stockList) {
      this.utilVue.loadShow(true)
      let stockIds = stockList.map(item => {
        if (item.stockId) {
          return item.stockId
        }
        return item.id
      })
      let params = {
        stockIds,
        useId: this.form.id,
        oprtCode: this.form.oprtCode,
        flagUseRedType: this.form.flagUseRedType
      }
      this.$ajax.post('/dept/oprt_use_item/saveByOprtSn', params).then((resp) => {
        this.utilVue.loadHide()
        if (resp.code == 0) {
          this.utilMessage.success(resp.msg)
          this.loadDtl()
          this.afterTableDataChange()
        }
      })
    },

    // 明细 新增、删除、修改后调用
    afterTableDataChange() {
      this.utils.refreshRefs(this)
    },
    // 验证表单
    formValid() {
      if (!this.form.oprtCode && !this.form.patientId) {
        this.utilMessage.warning('手术单号和患者至少选择一个')
        return false
      }
      return true
    },

    // 打印
    doPrint() {
      let wrapper = this.$newWrapper().eq('deptOprtUseId', this.form.id)
      let params = {
        queryString: JSON.stringify(wrapper.queryConditions)
      }
      this.utilVue.loadShow(true)
      let that = this
      this.$ajax.get(`/dept/oprt_use/getPrintData/${this.form.id}`, {params}).then(resp => {
        this.utilVue.loadHide()
        console.log('resp', resp)
        if (resp.success) {
          let param = {
            isStaticHtml: true,
          }
          this.dataListPrint = resp.data
          param.staticHtmlGet = this.staticHtmlGet
          global.utilPrint.openFormPrint(param)
        }
      })
    },
    staticHtmlGet(pageDataEvery = 20){
      let that = this
      let param = {
        isStaticHtml: true,
      }
      let dataList = this.dataListPrint
      // 表头样式
      let titleStyle = '  style="text-align: center;font-size: 20px;padding: 9px 0px;font-weight: bold;letter-spacing: 3px;" '
      // 页数样式
      let pageSizeStyle = '  style="font-size: 13px;position: absolute;right: 4%;" '
      // 表格样式
      let tableStyle = '  style="width: 100%;text-align: center;border-collapse: collapse;    table-layout: fixed;" '
      // 表格样式
      let tableStyleSign = '  style="width: 100%;text-align: center;border-collapse: collapse;    table-layout: fixed;   " '
      // let tableStyleSign = '  style="width: 100%;text-align: center;border-collapse: collapse;    table-layout: fixed;  " '
      // 表格标题样式
      let tdStyleLabel = '  style="border:1px solid black;width: 80px;min-width: 80px;max-width: 80px;font-weight: bold;word-break: break-all;    padding: 5px 0px;    font-size: 12px; " '
      let tdDateHeadStyleLabel = '  style="border:1px solid black;width: 80px;min-width: 80px;max-width: 80px;font-weight: bold;word-break: break-all;    padding: 5px 0px;    font-size: 12px; height: 33px; max-height:33px; min-height:33px; " '
      let tdStyleSeq = '  style="border:1px solid black;width: 50px;min-width: 50px;max-width: 50px;font-weight: bold;word-break: break-all;    padding: 5px 0px;    font-size: 12px; height: 30px; max-height:30px; " '
      let tdStyleLabel123 = '  style="border:1px solid black;width: 60px;min-width: 60px;max-width: 60px;font-weight: bold;word-break: break-all;    padding: 5px 0px;    font-size: 12px; " '
      // 表格值样式
      let tdStyleValue = '  style="border:1px solid black;    word-break: break-all;    font-size: 12px;" '
      let tdDataStyleValue = '  style="border:1px solid black;    word-break: break-all;    font-size: 11px;" '
      // 数据左侧标题样式
      let tdLeftStyle = ' style="border: 1px solid black;width: 60px;min-width: 60px;max-width: 60px;padding: 10px 10px;font-weight: bold;    font-size: 12px;" '
      // 分页
      let pageBreakHtml = ' <div class="pagebreak" style="page-break-after:always">&nbsp;&nbsp;&nbsp;</div> '
      // 数据左侧标题跨行,有多少条数据既有多少行 + 1
      let rowspanData = 2
      // 右侧列跨多少列
      let colspanRightEnd = 1
      let staticHtmlArr = []
      let addIndex = 0
      // 总页数
      let pageTotal = 0
      dataList.forEach(main => {
        pageTotal += Math.ceil(main.dtlList.length / pageDataEvery)
      })
      let dataSeq = 1
      let styleTitle2 = '  style="font-weight: bold;font-size: 12px;text-align: left;" '
      let styleTitle2Text = '  style="font-weight: 200; padding-left:10px" '
      dataList.forEach(main => {
        let totalPage = Math.ceil(main.dtlList.length / pageDataEvery)
        for(let pageCurr = 0; pageCurr　< totalPage; pageCurr++) {
          let dtlListSub
          if (main.dtlList.length < pageDataEvery * (pageCurr + 1) ) {
            dtlListSub = main.dtlList.slice(pageDataEvery * pageCurr,main.dtlList.length)
          } else {
            dtlListSub = main.dtlList.slice(pageDataEvery * pageCurr,pageDataEvery * (pageCurr + 1))
          }
          rowspanData = dtlListSub.length + 1
          staticHtmlArr.push(`<div ${titleStyle} class="dataTableBox">无菌高耗使用对接表`)
          staticHtmlArr.push(`<span ${pageSizeStyle}>总页数:${pageTotal},当前页:${addIndex + 1}</span>`)
          staticHtmlArr.push(`</div>`)
          staticHtmlArr.push(`<div  ${styleTitle2}>消耗单号: <span ${styleTitle2Text}>${that.form.busKey}</span></div>`)
          staticHtmlArr.push(`<table ${tableStyle}>`)
          staticHtmlArr.push(`    <tr>`)
          staticHtmlArr.push(`        <td ${tdStyleLabel123} colspan="2">姓名</td><td ${tdStyleValue}>${this.strings.defaultIfBlank(main.patientName, '')}</td>`)
          staticHtmlArr.push(`        <td ${tdStyleLabel123}>性别</td><td ${tdStyleValue}>${this.strings.defaultIfBlank(main.patientSex, '')}</td>`)
          staticHtmlArr.push(`        <td ${tdStyleLabel123}>年龄</td><td ${tdStyleValue}>${this.strings.defaultIfBlank(main.patientAge, '')}</td>`)
          staticHtmlArr.push(`        <td ${tdStyleLabel}>科室</td><td ${tdStyleValue} colspan="2">${this.strings.defaultIfBlank(main.deptName, '')}</td>`)
          staticHtmlArr.push(`    </tr>`)
          staticHtmlArr.push(`    <tr>`)
          staticHtmlArr.push(`        <td ${tdStyleLabel} colspan="2">床号</td><td ${tdStyleValue}>${this.strings.defaultIfBlank(main.bedNo, '')}</td>`)
          staticHtmlArr.push(`        <td ${tdStyleLabel}>住院号</td><td colspan="${colspanRightEnd}" ${tdStyleValue}>${this.strings.defaultIfBlank(main.inpatientNo, '')}</td>`)
          staticHtmlArr.push(`        <td ${tdStyleLabel}>消耗日期</td><td ${tdStyleValue} colspan="4">${this.dates.toDate(main.busDate, 'yyyy-MM-dd')}</td>`)
          staticHtmlArr.push(`    </tr>`)
          staticHtmlArr.push(`    <tr>`)
          staticHtmlArr.push(`        <td ${tdStyleLabel} colspan="2">临床诊断</td><td ${tdStyleValue}>${this.strings.defaultIfBlank(main.diagnosis, '')}</td>`)
          staticHtmlArr.push(`        <td ${tdStyleLabel}>手术名称</td><td colspan="6" ${tdStyleValue}>${this.strings.defaultIfBlank(main.oprtName, '')}</td>`)
          // staticHtmlArr.push(`        <td ${tdStyleLabel}>配送企业</td><td ${tdStyleValue} colspan="4">${this.strings.defaultIfBlank(main.supplierName, '')}</td>`)
          staticHtmlArr.push(`    </tr>`)
          staticHtmlArr.push(`    <tr>`)
          staticHtmlArr.push(`        <td rowspan="${rowspanData}" ${tdLeftStyle}>手术已使用耗材</td>`)
          staticHtmlArr.push(`        <td  ${tdStyleSeq}>序号</td>`)
          staticHtmlArr.push(`        <td ${tdDateHeadStyleLabel}>产品名称</td>`)
          staticHtmlArr.push(`        <td ${tdDateHeadStyleLabel}>规格型号</td>`)
          staticHtmlArr.push(`        <td ${tdDateHeadStyleLabel}>厂家</td>`)
          staticHtmlArr.push(`        <td ${tdDateHeadStyleLabel}>数量</td>`)
          staticHtmlArr.push(`        <td ${tdDateHeadStyleLabel}>批号</td>`)
          staticHtmlArr.push(`        <td ${tdDateHeadStyleLabel}>产品注册证</td>`)
          staticHtmlArr.push(`        <td ${tdDateHeadStyleLabel}>标签码</td>`)
          staticHtmlArr.push(`        <td ${tdDateHeadStyleLabel}>UDI</td>`)
          staticHtmlArr.push(`    </tr>`)
          dtlListSub.forEach(dtl => {
            staticHtmlArr.push(`    <tr>`)
            staticHtmlArr.push(`        <td ${tdDataStyleValue}>${dataSeq}</td>`)
            staticHtmlArr.push(`        <td ${tdDataStyleValue}>${this.strings.defaultIfBlank(dtl.matrName, '')}</td>`)
            staticHtmlArr.push(`        <td ${tdDataStyleValue}>${this.strings.defaultIfBlank(dtl.matrSpec, '')}</td>`)
            staticHtmlArr.push(`        <td ${tdDataStyleValue}>${this.strings.defaultIfBlank(dtl.mfgName, '')}</td>`)
            staticHtmlArr.push(`        <td ${tdDataStyleValue}>${this.strings.defaultIfBlank(dtl.skuQty, '')}</td>`)
            staticHtmlArr.push(`        <td ${tdDataStyleValue}>${this.strings.defaultIfBlank(dtl.lot, '')}</td>`)
            staticHtmlArr.push(`        <td ${tdDataStyleValue}>${this.strings.defaultIfBlank(dtl.certificateNo, '')}</td>`)
            staticHtmlArr.push(`        <td ${tdDataStyleValue}>${this.strings.defaultIfBlank(dtl.sn, '')}</td>`)
            staticHtmlArr.push(`        <td ${tdDataStyleValue}>${this.strings.defaultIfBlank(dtl.udi, '')}</td>`)
            staticHtmlArr.push(`    </tr>`)
            dataSeq += 1
          })

          staticHtmlArr.push(`</table>`)
          // 签字区域
          let style1 = 'style="  width: 135px;min-width: 135px; max-width: 135px;font-weight: bold;padding: 5px 0px;text-align:left"'
          staticHtmlArr.push(`<table ${tableStyleSign}>`)
          staticHtmlArr.push(`    <tr>`)
          staticHtmlArr.push(`        <td ${style1}>使用科室主任签字:</td>`)
          staticHtmlArr.push(`        <td  ${style1}>手术室签字:</td>`)
          staticHtmlArr.push(`        <td ${style1}>医学装备科签字:</td>`)
          staticHtmlArr.push(`    </tr>`)
          staticHtmlArr.push(`</table>`)

          // 合格证粘贴区域
          // let styleTxt = 'style="    font-weight: bold;padding: 5px 0px;"'
          // let styleBox = 'style="    height: 400px;border: 1px dotted black;"'
          // staticHtmlArr.push(`<div ${styleBox}>`)
          // staticHtmlArr.push(`    <div ${styleTxt}>合格证粘贴处:</div>`)
          // staticHtmlArr.push(`</div>`)
          // 不是最后一页，追加分页
          addIndex+=1
          if (addIndex != pageTotal) {
            staticHtmlArr.push(pageBreakHtml)
          }
        }
      })

      let styleRootBox = 'style="width: 92%; max-width: 92%;margin-left: 4%; max-height: 98%; margin-top: 4%; margin-bottom: 1%;"'
      return `<div  ${styleRootBox}> ${staticHtmlArr.join('')}</div>`
    }
  },
  created() {
    let that = this
    this.$emit('event-register', {
      validate: (callback) => {
        return this.$refs.editForm.validate(callback)
      },
      beforeSave: () => {
        if (!that.formValid()) {
          return false
        }
        this.$emit('data-callback', this.form)
        return true
      },
      afterMove: (formData, initData) => {
        this.form = global.utils.jsonClone(formData)

        // 新增，设置默认值
        if (!this.form.id) {
          this.$set(this.form, 'busDate', new Date().format('yyyy-MM-dd'))
          this.$set(this.form, 'busType', 'MANUAL')
          this.$set(this.form, 'flagUseRedType', 0)
          if (this.strings.isNotBlank(this.utils.getCurrentWarehouse().warehouseId)) {
            this.$set(this.form, 'warehouseId', this.utils.getCurrentWarehouse().warehouseId)
            this.$set(this.form, 'warehouseName', this.utils.getCurrentWarehouse().warehouseName)
          }
          if (this.propParent.cpFormNew) {
            this.$set(this.form, 'deptId', this.utils.getCurrentUser().deptId)
            this.$set(this.form, 'deptName', this.utils.getCurrentUser().deptName)
          }
        }
        this.loadDtl()
      },
      afterSave: () => {
      },
      beforeDelete: () => {
        return true
      },
      afterDelete: () => {},
      beforeFlow: (flowButtonKey) => {
        if (!that.cpHasDtl) {
          this.utilMessage.error('消耗明细为空，不能提交')
          return false
        }
        return true
      },
      afterFlow: (flowButtonKey) => {},
      beforeClose: () => {
        return true
      },
      async afterClick(button, data, viewForm) {
        let {key: buttonKey} = button
        if (buttonKey == 'preview') {
          that.doPrint()
        }
        if (buttonKey == 'red') {
          let params = {id: data.id}
          that.utilMessage.confirm('此操作将冲红此单据, 是否继续?', () => {
            that.utilVue.loadShow(true)
            that.$ajax.post('/dept/oprt_use/toRedById', params).then(res => {
              if (res.code == 0) {
                that.utilVue.loadHide()
                that.utilMessage.confirm(`冲红成功，是否打开冲红单据【${res.data.busKey}】?`, () => {
                  that.propParent.viewRowOne(res.data.id)
                }, () => {
                  that.afterTableDataChange()
                })
              }
            })
          })
        } else if (buttonKey == 'audit') {
          let idList = []
          idList.push(data.id)
          // 科室审核
          that.utilVue.loadShow(true)
          that.$ajax.post('/dept/oprt_use/auditDeptOprtUse', idList).then(res => {
            if (res.code == 0) {
              that.utilMessage.success(res.msg)
              that.utilVue.loadHide()
              that.propParent.tablePage.currentPage = 1
              that.propParent.ocRefresh()
              that.utils.refreshRefs(that)
            }
          })
        }
      }
    })
  },
  props: {
    propParent: Object,
    propInitData: Object,
    propPrimaryKey: String,
    propDictionaries: Object,
    propCurrentRow: Object,
    propViewFormData: Object,
    propReadonly: Boolean,
    propStatus: String,
    propRules: Object,
    propParam: Object,
  },
  components: {
    customAnchor
  },
}
</script>
